/*改变颜色*/
const btn = document.querySelector("button");

function random(number) {
  return Math.floor(Math.random() * (number + 1));
}

function changeBackground() {
  const rndCol = `rgb(${random(255)}, ${random(255)}, ${random(255)})`;
  document.body.style.backgroundColor = rndCol;
}

btn.addEventListener("click", changeBackground);

/*上传图片更新 */
const fileInput = document.getElementById("file");
const img = document.getElementById("my-image");

// 成功上传图片后，将新的图片源替换掉旧的图片源
fileInput.addEventListener("change", (event) => {

  const file = event.target.files[0];
  const reader = new FileReader();
  reader.onload = (e) => {
    img.src = e.target.result;
  };
  reader.readAsDataURL(file);

});
